import { createRouter, createWebHashHistory } from 'vue-router'
import home from '@renderer/views/home/index.vue'
import account from '@renderer/views/account/index.vue'
import VideoEditView from '@renderer/views/video-edit/VideoEditView.vue'
import BatchView from '@renderer/views/batch/BatchView.vue'
import ApiKeysManagement from '@renderer/views/key/ApiKeysManagement.vue';
import IPAddressesManagement from '@renderer/views/system/IPAddressesManagement.vue'
import AssetPaths from '@renderer/views/system/AssetPaths.vue'
import IframeView from '@renderer/views/web/IframeView.vue'
import ChangeView from '@renderer/views/web/ChangeView.vue'
import SubsView from '@renderer/views/system/SubsView.vue'
import { getBaseUrl } from '@renderer/api/assetPaths'
import { ref } from 'vue'

const assetPaths = ref('')

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      name: 'root',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: home
    },
    {
      path: '/video/edit',
      name: 'videoEdit',
      component: VideoEditView
    },
    {
      path: '/batch',
      name: 'batch',
      component: BatchView
    },
    {
      path: '/audio',
      name: 'audio',
      component: () => import('../views/audio/SpeechSynthesisView.vue')
    },
    {
      path: '/tts-video-creation',
      name: 'TtsVideoCreation',
      component: () => import('../views/audio/components/TtsVideoCreationView.vue')
    },
    {
      path: '/change',
      name: 'change',
      component: ChangeView,
      props: (route) => ({
        src: route.query.src || assetPaths.value + ":8080" // 默认值
      })
    },
    {
      path: '/subs',
      name: 'subs',
      component: SubsView,
    },
    {
      path: '/key',
      name: 'key',
      component: ApiKeysManagement,
      meta: {
        title: 'API密钥管理'
      }
    },
    {
      path: '/ip-management',
      name: 'IPManagement',
      component: IPAddressesManagement
    },
    {
      path: '/info',
      name: 'info',
      component: () => import('../views/system/infoView.vue')
    },
    {
      path: '/file',
      name: 'file',
      component: AssetPaths,
    },
    {
      path: '/kpop',
      name: 'kpop',
      component: IframeView,
      props: (route) => ({
        src: route.query.src || assetPaths.value + ":5173" // 默认值
      })
    },
    {
      path: '/account',
      name: 'account',
      component: account
    },
  ]
})

await getBaseUrl().then(result => {
  assetPaths.value = result;
})

export default router
